#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef long long LL;
#define x first
#define y second
typedef pair<pair<int, int>, pair<int, int>> PII;
const int N = 2e5 + 10;
LL a[N];
int l[N], r[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		priority_queue<PII, vector<PII>, greater<PII>>heap;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i != 1 && i != n) {
				l[i] = i - 1;
				r[i] = i + 1;
			}
			if (i == 1)l[i] = -1;
			if (i == n)r[i] = -1;
			//heap.push({ a[i],i }, { l[i], r[i] });
		}
		LL ans = 0;
		while (heap.size()) {
			PII t = heap.top();
			heap.pop();
			LL x1 = 0, x2 = 0;
			int idx1 = t.y.x;
			int idx2 = t.y.y;
			bool flag1 = 0, flag2 = 0;
			if (idx1 != -1) {
				a[idx1 + 1] += a[idx1];
				l[idx1 + 1] = l[idx1];
				flag1 = 1;
			}
			if (idx2 != -1) {
				a[idx2 - 1] += a[idx2];
				r[idx2 - 1] = r[idx2];
				flag2 = 1;
			}
			if (flag1 + flag2 >= 1) {
				if (flag1 + flag2 == 1) {
					
				}
			}
		}
	}
	return 0;
}